﻿using K9Nano.Dict;
using Microsoft.AspNetCore.Mvc;

namespace K9Nano.AspNetCore.Controllers;

[Route("api/dict")]
public class DictController(IDictResolverFactory factory): ApiControllerBase
{
    /// <summary>
    /// 根据字典名称获取字典数据接口
    /// </summary>
    /// <param name="name">字典名称</param>
    [HttpGet("data/{name}")]
    public async Task<KeyValuePair<string, string>[]> GetDictData(string name)
    {
        var resolver = factory.Create(name);
        if(resolver == null) return [];
        return await resolver.GetAsync(HttpContext.RequestAborted);
    }

    /// <summary>
    /// 获取所有字典数据的元数据
    /// </summary>
    [HttpGet("all")]
    public KeyValuePair<string, string>[] GetAllDict()
    {
        return factory.GetAllDictMeta();
    }
}
